const express = require('express');
const fs = require('fs').promises;
const path = require('path');
const app = express();
const jsonFilePath = path.join(__dirname, '..', 'player', 'player.json');

app.get('/', async (req, res) => {
  let users = await readJsonFile(jsonFilePath)
  let list = []
  users.forEach((user) => {
    list.push(user)
  })
  res.send({ code: 200, msg: '获取成功', data: list })

});

async function readJsonFile(filePath) {
  try {
    const data = await fs.readFile(filePath, 'utf8');
    return JSON.parse(data);
  } catch (err) {
    throw err;
  }
}
module.exports = app;